﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Collections;

namespace VisualStudioEnv
{
    public class VSSolution
    {
        private DTE dte;
        private Solution solution;
        public string Name { get; private set; }

        public VSSolution(DTE dte)
        {
            this.dte = dte;
        }

        public void Open(string solutionFile)
        {
            solution = dte.Solution;

            solution.Open(solutionFile);

            this.Name = solution.FullName;
        }

        public IEnumerable<VSProject> Projects
        {
            get
            {
                foreach (Project project in solution.Projects)
                {
                    yield return new VSProject(project);
                }
            }
        }

        public IEnumerable<ProjectItem> EDMXModels
        {
            get
            {
                foreach (Project project in solution.Projects)
                {
                    foreach (ProjectItem item in project.ProjectItems)
                    {
                        if (item.Name.EndsWith(".edmx"))
                        {
                            yield return item;
                        }
                    }
                }
            }
        }
    }
}
